# -*- python -*-
# vim: ft=python:

# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os

from buildbot.scheduler import Nightly

from master import build_utils
from master import master_utils
from master import slaves_list
from master.factory import annotator_factory

import config
import master_site_config

ActiveMaster = master_site_config.Gatekeeper

MAIL_NOTIFIER = False

c = BuildmasterConfig = {}

c['slavePortnum'] = ActiveMaster.slave_port

config.DatabaseSetup(c)

####### SCHEDULERS

# Actually 'Minutely' instead of 'Nightly.' It kicks off a run every minute.
s_chromium_gatekeeper = Nightly(name='gatekeeper',
                                branch=None,
                                minute='*',
                                builderNames=['Chromium Gatekeeper',
                                              'Chromium Gatekeeper Failure'])

c['schedulers'] = [s_chromium_gatekeeper]


# ----------------------------------------------------------------------------
# FACTORIES

factory_obj = annotator_factory.AnnotatorFactory()

f_chromium_gatekeeper = factory_obj.BaseFactory('gatekeeper')
f_chromium_gatekeeper_failure = factory_obj.BaseFactory('gatekeeper-failure')

# ----------------------------------------------------------------------------
# BUILDER DEFINITIONS

b_chromium_gatekeeper = {
  'name': 'Chromium Gatekeeper',
  'builddir': 'gatekeeper',
  'factory': f_chromium_gatekeeper,
  'auto_reboot' : False,
}

b_chromium_gatekeeper_failure = {
  'name': 'Chromium Gatekeeper Failure',
  'builddir': 'chromium-gatekeeper-failure',
  'factory': f_chromium_gatekeeper_failure,
  'auto_reboot' : False,
}

c['builders'] = [b_chromium_gatekeeper,
                 b_chromium_gatekeeper_failure]

# Associate the slaves to the builders. The configuration is in slaves.cfg.
slaves = slaves_list.SlavesList('slaves.cfg', 'Gatekeeper')
for builder in c['builders']:
  builder['slavenames'] = slaves.GetSlavesName(builder=builder['name'])

####### BUILDSLAVES

c['slaves'] = master_utils.AutoSetupSlaves(c['builders'],
                                           config.Master.GetBotPassword())

# Make sure everything works together.
master_utils.VerifySetup(c, slaves)


####### STATUS TARGETS

c['logCompressionLimit'] = False
c['projectName'] = ActiveMaster.project_name
c['projectURL'] = config.Master.project_url
# Must come before AutoSetupMaster().
c['buildbotURL'] = ActiveMaster.buildbot_url

master_utils.AutoSetupMaster(c, ActiveMaster, MAIL_NOTIFIER)

# Do it at the end to override values set by AutoSetupMaster, the default is
# too low. Must keep at least a few days worth of builds.
c['buildHorizon'] = 3000
c['logHorizon'] = 3000
# Must be at least 2x the number of slaves.
c['eventHorizon'] = 200

